import {Switch,Route,Redirect} from "react-router-dom"
import {Suspense} from "react"
let RouterView = (props)=>{
    let {RouterList} = props
    console.log(RouterList,11)
    let routerlist = RouterList.filter((item,index)=>{
        return !item.to
    })
    let redireact =  RouterList.filter((item,index)=>{
        return item.to
    })[0]
    console.log(redireact);
    return (
        <Suspense fallback={<div>...loading</div>}>
            <Switch>
                {
                    routerlist&&routerlist.length?routerlist.map((item,index)=>{
                        return <Route path={item.path} key={index} render={(routerProps)=>{
                            return <item.component {...routerProps} navlink={routerlist}></item.component>
                        }}></Route>
                    }):""
                }
                {
                    redireact?<Redirect to={redireact.to} from={redireact.from}></Redirect>:"暂无从定向"
                }

            </Switch>
        </Suspense>
    )
}
export default RouterView